package org.clockworkmages.games.anno1186.situations.inventory;

import java.util.List;

import org.clockworkmages.games.anno1186.GameBeansContext;
import org.clockworkmages.games.anno1186.GameStateService;
import org.clockworkmages.games.anno1186.model.character.PlayerCharacter;
import org.clockworkmages.games.anno1186.model.item.Item;
import org.clockworkmages.games.anno1186.model.option.GoBackOption;
import org.clockworkmages.games.anno1186.model.option.Option;
import org.clockworkmages.games.anno1186.model.situation.Situation;
import org.clockworkmages.games.anno1186.situations.inventory.options.EquippedItemOption;
import org.clockworkmages.games.anno1186.situations.inventory.options.InventoryItemOption;

public class InventorySituation
		extends Situation {

	public InventorySituation() {
		super("ST_INVENTORY");
		setTitle("Inventory");

	}

	@Override
	public void update() {
		super.update();
		GameStateService gameStateService = GameBeansContext
				.getBean(GameStateService.class);

		PlayerCharacter playerCharacter = gameStateService.getGameState()
				.getCharacter();

		List<Option> options = getOptions();
		options.clear();

		String text = "";

		if (playerCharacter.getInventory().size() > 0) {
			text += "\nYou carry following items: \n";
			for (Item item : playerCharacter.getInventory()) {
				text += " - " + item.getName() + "\n";
				options.add(new InventoryItemOption(item));
			}
		}

		if (playerCharacter.getEquippedItems().size() > 0) {
			text += "\nYou have following items equipped: \n";
			for (Item equippedItem : playerCharacter.getEquippedItems()
					.values()) {
				text += " - " + equippedItem.getName() + "\n";
				options.add(new EquippedItemOption(equippedItem));
			}
		}

		setText(text);

		options.add(GoBackOption.INSTANCE);
	}

}
